home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_02_03
/
2n03006b
< prev
next >
Wrap
Text File
|
1991-01-12
|
2KB
|
82 lines
/*
* Listing 2: Print the screen to an Epson-compatible
* graphics printer. (Link this with Listing 1.)
*/
#include <io.h>
#include <graphics.h>
#define ESC 0x1b /* escape */
#define CR 0x0d /* carriage return */
#define LF 0x0a /* line feed */
/* global variables
*/
extern int x_max, y_max;
extern int print_fh;
/* prototypes
*/
void print_stripe( int y_start );
void print_screen( void )
{
static char line_sp[3] = {ESC, 'A', 0x08};
static char reset_prn[2] = {ESC, '@'};
int y;
/* Send ESC A 08 to set line spacing to 8 dot rows.
*/
write(print_fh, line_sp, 3);
/* Send the data in groups of 8 dots rows at a time,
* starting with row 0, then 8, 16...
*/
for (y = 0; y < y_max; y += 8)
print_stripe(y);
/* Send ESC @ to return the printer to defaults.
*/
write(print_fh, reset_prn, 2);
}
/*
* Send one "stripe" of pixels to the printer, beginning
* with the given Y-coordinate. A stripe is 8 dots high,
* and as wide as the screen.
*/
void print_stripe( int y_start )
{
int num_pix, x, y, bit_num;
unsigned char out_pixel;
static char graph_cmd[4] = {ESC, 'K', 0, 0};
static char cr_lf[2] = {CR, LF};
/* Send ESC K n1 n2, where (256 * n2) + n1 is the
* number of pixels across a line.
*/
num_pix = x_max + 1;
graph_cmd[2] = num_pix & 0xff;
graph_cmd[3] = num_pix >> 8;
write(print_fh, graph_cmd, 4);
for (x = 0; x < num_pix; ++x)
{
/* Accumulate 8 pixels, vertically, into out_pixel.
*/
out_pixel = 0;
y = y_start;
for (bit_num = 7; bit_num >= 0; --bit_num, ++y)
{
if (getpixel(x, y) > 0)
out_pixel |= (1 << bit_num);
}
write(print_fh, &out_pixel, 1);
}
/* Send carriage return, line feed.
*/
write(print_fh, cr_lf, 2);
}